﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.core {
    import flash.display.*;
    import reprise.i18n.*;
    import reprise.services.tracking.*;
    import flash.utils.*;

    public class ApplicationContext {

        public var coreResourceLoader:CoreResourceLoader;
        protected var m_i18nService:II18NService;
        protected var m_trackingService:ITrackingService;
        public var applicationParameters:Object;
        protected var m_application:Application;
        public var applicationURL:String;

        protected static var g_mainContext:ApplicationContext;

        public function ApplicationContext(_arg1:Application, _arg2:LoaderInfo){
            var _local4:String;
            super();
            coreResourceLoader = new CoreResourceLoader(this);
            var _local3:ByteArray = new ByteArray();
            _local3.writeObject(_arg1.stage.loaderInfo.parameters);
            _local3.position = 0;
            applicationURL = _arg1.applicationURL();
            applicationParameters = _local3.readObject();
            if (_arg2.url != _arg1.stage.loaderInfo.url){
                for (_local4 in _arg2.parameters) {
                    applicationParameters[_local4] = _arg2.parameters[_local4];
                };
            };
        }
        public function setTrackingService(_arg1:ITrackingService):void{
            m_trackingService = _arg1;
        }
        public function track(_arg1:String):void{
            m_trackingService.track(_arg1);
        }
        public function setI18NService(_arg1:II18NService):void{
            m_i18nService = _arg1;
        }
        public function i18n(_arg1:String, _arg2=null){
            var _local3:*;
            if (!m_i18nService){
                log((("w No i18n service set, can't resolve key \"" + _arg1) + "\""));
                return (((_arg2 == null)) ? _arg1 : _arg2);
            };
            if (m_i18nService.keyExists(_arg1)){
                _local3 = m_i18nService.contentByKey(_arg1);
                if (typeof(_local3) == "string"){
                    _local3 = (_local3 as String).split("\r\n").join("\n").split("\r").join("\n");
                };
            };
            if (_local3 == null){
                log((("w No i18n result found for key \"" + _arg1) + "\""));
                return (((_arg2 == null)) ? _arg1 : _arg2);
            };
            return (_local3);
        }

    }
}//package reprise.core 
